<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      var sortColors = function (nums) {
        let left = 0
        let right = nums.length - 1
        let i = 0
        while (i <= right) {
          if (nums[i] == 0) {
            ;[nums[i], nums[left]] = [nums[left], nums[i]]
            i++
            left++
          } else if (nums[i] == 1) {
            i++
          } else {
            ;[nums[i], nums[right]] = [nums[right], nums[i]]
            right--
          }
        }
        return nums
      }
    </script>
  </body>
</html>
